home *** CD-ROM | disk | FTP | other *** search
/ Birds of My State or Province 4.5 / eField Guide Viewer.iso / pc / Windows / CR115.cab / HTMLViewerBridge.asp.09012B1E_8731_4B9A_8C8B_6CA68543BF28 < prev    next >
Encoding:
Text File  |  2006-01-16  |  6.0 KB  |  227 lines

  1. <!--
  2.   File Version Start - Do not remove this if you are modifying the file
  3.   Build: 11.0.0
  4.   File Version End
  5.  
  6.     (c) 2004 Business Objects, Inc.  All rights reserved.
  7.     This code or any derivative work thereof may not be distributed without the express written
  8.     permission of Business Objects.
  9. -->
  10. <%@ Language=JScript codepage=65001 %>
  11. <%
  12. // *********************************************************************
  13. // SERVER-SIDE STRING VARIABLES FOR LOCALIZING
  14. // *********************************************************************
  15. var L_SESSION_EXPIRED = "Unable to retrieve Object.";
  16. var L_INVALID_RPTSRC = "ReportSource invalid.";
  17. var L_INVALID_ARGUMENT ="Invalid query. Need a report id or ReportSource variable."
  18. // *********************************************************************
  19. %>
  20.  
  21. <%
  22. Session.CodePage = 65001;
  23. Response.ContentType = "text/html; charset=utf-8";
  24. Response.Write("<meta http-equiv=content-type content=\"text/html; charset=utf-8\">");
  25.  
  26. function PreventCaching()
  27. {
  28.     // prevent browser from caching the page
  29.     var cache_date = new Date();
  30.     cache_date.setFullYear( cache_date.getFullYear() - 1 );
  31.     Response.ExpiresAbsolute = cache_date.getVarDate();
  32. }
  33.  
  34. function GetSession(name)
  35. {
  36.     return Session.Contents(name);
  37. }
  38.  
  39. function SetSession(name, value)
  40. {
  41.     Session.Contents(name) = value;
  42. }
  43.  
  44. function RemoveSession(name)
  45. {
  46.     Session.Contents.Remove(name);
  47. }
  48.  
  49. function GetApplication(name)
  50. {
  51.     return Application.Value(name);
  52. }
  53.  
  54. function SetApplication(name, value)
  55. {
  56.     Application.Value(name) = value;
  57. }
  58.  
  59. function GetQueryString(name)
  60. {
  61.     var s =  Request.QueryString.Item(name);
  62.     if (s.Count > 0) return s;
  63.     return null;
  64. }
  65.  
  66. function EnsureImageCleanerIsRunning()
  67. {
  68.   if ( GetSession("imageCleanerRunning"))
  69.     return;
  70.  
  71.   Application.Lock();
  72.   if (!GetApplication("theCrystalImageCleaner") || typeof(GetApplication("theCrystalImageCleaner")) != "object")
  73.   {
  74.     var cleaner = Server.CreateObject("CrystalReports.CrystalImageCleaner");
  75.     cleaner.Start(120000, 120000); // 2 min, 2 min
  76.     SetApplication("theCrystalImageCleaner", cleaner);
  77.   }
  78.   Application.Unlock();
  79.  
  80.   // Store a flag in session so I don't have to check the application object every time.
  81.   SetSession ("imageCleanerRunning", 1);  // Must be anything but an empty string
  82. }
  83. //-------start----------
  84. PreventCaching();
  85.  
  86. try
  87. {
  88.     // Get parameters, build uri query string
  89.     var rptsrckey;  //reportsource is stored here
  90.     var rptid;      //report id for managed case or reportsource session variable for unmanaged case
  91.     
  92.     var init =  GetQueryString( "init" ) ;
  93.     if(init != null)
  94.     {
  95.         var initStr = String(init).toLowerCase();
  96.         var index = initStr.indexOf("java");
  97.         if (index < 0)
  98.             index = initStr.indexOf("actx")
  99.         if (index >= 0)
  100.         {
  101.             //if not html viewer, go back to reportsourcebridge entry.
  102.             var query = String (Request.ServerVariables.Item("QUERY_STRING"));
  103.             Response.Redirect ("./viewrpt.asp?" + query);    
  104.         }        
  105.     }
  106.       
  107.     
  108.     
  109.     var id =  GetQueryString( "id" ) ;
  110.     var uriQueryString;
  111.     var rptSrc;
  112.     if (id == null)
  113.     { 
  114.         var rptsrckey =  GetQueryString( "rptsrc" ) ;  // Use the cached report source 
  115.         if (rptsrckey == null)
  116.         {   
  117.             //reportsource stored by user is invalid
  118.             Response.Write( L_INVALID_ARGUMENT + "<BR>" );
  119.             Response.End;    
  120.         }
  121.         rptid = String(rptsrckey); 
  122.         rptSrc = GetSession(rptid);
  123.         if ( typeof(rptSrc) != "object")
  124.         {   
  125.             // can not find the reportsource user stored session just return error
  126.             Response.Write( L_INVALID_RPTSRC + "<BR>" );
  127.             Response.End;    
  128.         }
  129.         uriQueryString = "rptsrc=" + Server.URLEncode(rptid); 
  130.     } else
  131.     {
  132.         rptid = String(id);
  133.         rptsrckey = "rsbridge_rptsrc_" + rptid;
  134.         rptSrc = GetSession(rptsrckey); 
  135.         if ( typeof(rptSrc) != "object")
  136.         {
  137.             //can not find reportsource, maybe timeout, maybe user enter a new report id
  138.             var query = String (Request.ServerVariables.Item("QUERY_STRING"));
  139.             Response.Redirect ("./viewrpt.asp?" + query);
  140.         }        
  141.         uriQueryString = "id=" + rptid; 
  142.     }                 
  143.   
  144.   //everyting is fine, show the report  
  145.     EnsureImageCleanerIsRunning();
  146.     var viewer1 = Server.CreateObject( "CrystalReports.CrystalReportViewer" );
  147.  
  148.     var jobId =  GetQueryString( "jobId" ) ;
  149.     rptid += "_" + jobId;
  150.  
  151.     // set selection formula
  152.     var sfkey = "rsbridge_vtsf_" + rptid;   
  153.     var sf = GetSession(sfkey);
  154.     if ( typeof(sf) == "string") 
  155.     {
  156.         viewer1.ViewTimeSelectionFormula = String(sf);
  157.         RemoveSession(sfkey);
  158.     }
  159.  
  160.     var promptonrefresh =  GetQueryString( "promptonrefresh" );
  161.     if (promptonrefresh != null)
  162.     {
  163.         var bPrompt = String(promptonrefresh);
  164.         if (bPrompt == "0")
  165.         {
  166.             viewer1.ReuseParameterValuesOnRefresh = true;
  167.             uriQueryString += "&promptonrefresh=0";
  168.         }
  169.     }
  170.     
  171.     viewer1.ReportSource = rptSrc;
  172.     viewer1.IsOwnForm = true;
  173.     viewer1.IsOwnPage = true;
  174.     viewer1.IsDisplayGroupTree = true;
  175.     viewer1.PageToTreeRatio = 5.0;
  176.     viewer1.IsDisplayToolbar = true;
  177.     viewer1.IsDisplayPage = true;
  178.     viewer1.HasRefreshButton = true;
  179.     viewer1.URI = String(Request.ServerVariables.Item("SCRIPT_NAME")) + "?" + uriQueryString;
  180.  
  181.     var printControl =  GetQueryString( "advprint" ) ;
  182.     var printMode = 1;  // ActiveX print control
  183.     if (printControl != null)
  184.     {
  185.         printControl = String(printControl).toLowerCase();
  186.         if (printControl == "acro")
  187.         {
  188.             printMode = 0;        // Acrobat Reader print control
  189.         }
  190.     }        
  191.            
  192.     viewer1.PrintMode = printMode;
  193.  
  194.     var key = "rsbridge_connInfos_" + rptid;   
  195.     var connInfos = GetSession(key);
  196.     if ( typeof(connInfos) == "object") 
  197.     {
  198.         viewer1.DatabaseLogOnInfos = connInfos;
  199.         RemoveSession(key);
  200.     }
  201.         
  202.     key = "rsbridge_prompts_" + rptid;
  203.     var prompts = GetSession(key);
  204.     if ( typeof(prompts) == "object")
  205.     {
  206.         viewer1.ParameterFields = prompts;
  207.         RemoveSession(key);
  208.     } 
  209. }
  210. catch(e)
  211. {
  212.   Response.Write( L_SESSION_EXPIRED + "<BR>" );
  213.   Response.Write( e.description );
  214.   Response.End();
  215. }
  216.  
  217. try
  218. {
  219.     viewer1.ProcessHttpRequest( Request, Response, Session );
  220. }
  221. catch (e)
  222. {
  223.     // do not show the error message since the viewer will show a formatted message    
  224. }
  225. %>
  226.  
  227.